import 'babel-polyfill'
import 'classlist-polyfill'
import Vue from 'vue'
import VueRouter from 'vue-router'
import axios from './router/axios'
import VueAxios from 'vue-axios'
import App from './App'
import './permission' // 权限
import './error' // 日志
import router from './router/router'
import store from './store'
import { loadStyle } from './util/util'
import * as urls from '@/config/env'
import { iconfontUrl, iconfontVersion } from '@/config/env'
import * as filters from './filters' // 全局filter
import './styles/common.scss'

//引入elementUI
import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// 引入avue的包
import Avue from '@smallwei/avue';
// 引入avue的样式文件
import '@smallwei/avue/lib/index.css';

import 'jquery-ui-dist/jquery-ui'
import htmlToPdf from '@/views/util/htmlToPdf' //html转换为pdf

import './styles/stylus/APP.styl'

import VueQuillEditor from 'vue-quill-editor'
// require styles 引入样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
// echart引入
import echarts from 'echarts'

import basicContainer from './components/basic-container/main'

//详情页面注入
import bostechDetail from './components/bostech-detail/main'

//审批常用语
import commonWords from './components/bostech/commonWords'

//头部
import cardHeader from './components/bostech/card-header'

//申报单位树
import orgTree from './components/bostech/orgTree'

//申报单位树
import xieorgTree from './components/bostech/xieorgTree'

//规划底单弹窗
import detailDialog from './views/planning/achievement/detailDialog'

//附件组件
import preview from './components/file/preview'

//部门选择
import deptSelect from './components/dept/deptSelect'

import deptCheck from './components/dept/deptCheck'

import deptCheckNotDialog from './components/dept/deptCheckNotDialog'


import areaSelect from './components/area/areaSelect'

import assign from './components/activiti/assign'

import assignHistory from './components/activiti/assignHistory'

import processViewSimpleRegisterFlowsheet from '@/components/activiti/process-view/simple/register-flowsheet'

//地区代码树
import areaTree from './components/bostech/areaTree'

// 插件 json 展示
import vueJsonTreeView from 'vue-json-tree-view'

import { validatenull } from '@/util/validate'

//部门用户选择
import deptUserSelect from "@/components/dept-user-select/main"

Vue.prototype.validatenull = validatenull;

// 附件最多只能选一个
Vue.prototype.tipFileOne = function (files, fileList) { //changeData是函数名
  this.$message.warning("当前限制选择 1 个文件,如有修改请删除后重新添加！");
};


// 深度拷贝，避免指针赋值
Vue.prototype.deepClone = function (obj) { //obj是要拷贝的对象名
  let objClone = Array.isArray(obj)?[]:{};
  if(obj && typeof obj==="object"){
    for(let key in obj){
      if(obj.hasOwnProperty(key)){
        //判断ojb子元素是否为对象，如果是，递归复制
        if(obj[key]&&typeof obj[key] ==="object"){
          objClone[key] = Vue.prototype.deepClone(obj[key]);
        }else{
          //如果不是，简单复制
          objClone[key] = obj[key];
        }
      }
    }
  }
  return objClone;
};


Vue.use(Element);

Vue.use(Avue, { menuType: 'text' });

Vue.prototype.$echarts = echarts;

Vue.use(router);

Vue.use(vueJsonTreeView);

Vue.use(VueAxios, axios);

Vue.use(VueRouter);

Vue.use(VueQuillEditor);

Vue.use(htmlToPdf);

// 注册全局容器
Vue.component('basicContainer', basicContainer);

// 注册全局容器
Vue.component('bostechDetail', bostechDetail);

// 注册全局容器
Vue.component('commonWords', commonWords);

// 注册全局容器
Vue.component('cardHeader', cardHeader);

// 注册全局容器
Vue.component('xieorgTree', xieorgTree);

// 注册全局容器
Vue.component('detailDialog', detailDialog);

// 注册全局容器
Vue.component('preview', preview);

// 注册全局容器
Vue.component('orgTree', orgTree);

Vue.component("deptSelect", deptSelect);

Vue.component("deptCheck", deptCheck);

Vue.component("deptCheckNotDialog", deptCheckNotDialog);

Vue.component("deptUserSelect", deptUserSelect);

Vue.component("areaSelect", areaSelect);

Vue.component("assign", assign);

Vue.component("assignHistory", assignHistory);

Vue.component("processViewSimpleRegisterFlowsheet", processViewSimpleRegisterFlowsheet);


// 注册全局容器
Vue.component('areaTree', areaTree);

// 加载相关url地址
Object.keys(urls).forEach(key => {
  Vue.prototype[key] = urls[key]
});

//加载过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
});

// 动态加载阿里云字体库
iconfontVersion.forEach(ele => {
  loadStyle(iconfontUrl.replace('$key', ele))
});

// Vue.config.productionTip = false
if(process.env.NODE_ENV === 'development'){
  Vue.config.devtools = true;
}else {
  Vue.config.devtools = false;
}

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app');
